/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sample;

import com.sun.org.apache.xerces.internal.impl.dv.xs.DayDV;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;

/**
 *
 * @author dthanh
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Date date = new Date(System.currentTimeMillis());
        Schedules sch = new Schedules();
        XmlExport exporter = new XmlExport();
        while (true){
            Date curdate = new Date(System.currentTimeMillis());
            if (curdate.after(new Date(date.getTime()+86400000-86400000))){
                    if (sch.readSchedules(curdate)){
                        ArrayList<Schedule> list = sch.getList();

                        date = new Date(curdate.getTime()+86400000);
                    try {
                        exporter.exportSchedules(list, "schedules.xml");
                    } catch (ParserConfigurationException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (TransformerFactoryConfigurationError ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (TransformerException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    try {
                        Thread.sleep(86400000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    }
            }
        }
    }

}
